package com.onjob.recruit;

import java.sql.SQLException;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.onjob.security.Users;

import util.dao.HibernateDaoImpl;

public class CompanyDaoImpl extends HibernateDaoImpl<Company, String> implements
		CompanyDao {
	public Company getCompanyByUser(Users user) {
		Company company = (Company)this.getHibernateTemplate().find(
				"from " + Company.class.getName() + " c where c.userId.id="
						+ user.getId()).get(0);
		return company;
	}

	public void deleteCompanyFindByUser(final Long userId) {
		this.getHibernateTemplate().execute(
		new HibernateCallback(){
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				session.createQuery("delete from "+Company.class.getName()+" c where c.userId.id="+userId);
				return null;
			}
			
		});
	}
}
